﻿<%@ Page Language="vb" AutoEventWireup="false" Codebehind="Cwjk_Kjkm.aspx.vb" Inherits="PubProject.Cwjk_Kjkm"%>
<%@ Register TagPrefix="cc1" Namespace="Mysoft.CustomControl.AppGridEx" Assembly="Mysoft.CustomControl" %>
<%@ Register TagPrefix="mnu" Namespace="Mysoft.Map.Application.Menus" Assembly="Mysoft.Map.Application.Components"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
  <head>
    <title>会计科目设置</title>
    <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
    <meta name=vs_defaultClientScript content="JavaScript">
    <meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie3-2nav3-0">
    <script language="javascript" src="/Hyxt/js/Public.js"></script>
    <link rel="stylesheet" type="text/css" href="/_common/styles/global.css">
	<script language="javascript" src="/_controls/settings.aspx"></script>
	<link rel="stylesheet" type="text/css" href="/_nav/tabs.css">	
	<!-- Menu -->
	<LINK href="/_nav/menu.css" type="text/css" rel="stylesheet">
	<script language="javascript" src="/_common/scripts/global.js"></script>
	<script language="javascript" src="/_nav/menu.js"></script>
	<script language="javascript" src="/PubProject/js/Public.js"></script>

	<script language="javascript">
	    //在线帮助文件
	    var _MyHelpfile="/Cbgl/HELP/topics/财务人员/设置财务接口/会计科目设置.html";
        var MaxLevel = 0;
        var sIsUpdate = false;
        var sIsShowMsg = 1;
	    var IsEdit = false;
	    var IsChangeData = false; //判断是否更改数据
        
	    function window.onload() 
	    {
	        document.getElementById("txtCwztGUID").value=document.getElementById("__CwztGUID").value;
	        document.getElementById("txtApplication").value=document.getElementById("__Application").value;
            document.getElementById("txtCwztName").value=document.getElementById("__CwztName").value;
            document.getElementById("txtfuncid").value=document.getElementById("__funcid").value;
            sIsUpdate = false;

            if (document.all["txtApplication"] && document.all["txtApplication"].value == "0101") {
                _MyHelpfile = "/Slxt/HELP/topics/财务管理/财务接口设置/设置会计科目.html";
            }

	    }
	    function ReadyEnd()
	    {
	        RefreshLevel();
	    }
  //键盘按下事件
	    function KeyDown() { 
	        AppGridE1.event.cancelBubble = true;
	       
            //屏蔽输入法
            if (AppGridE1.event.keyCode == 9) {
                var oObj = AppGridE1.event.srcElement;
                
                while(true) {
                    if (oObj == AppGridE1.AppGridE_LeftDataDiv || oObj == AppGridE1.AppGridE_RightDataDiv) {
                        return;
                    }
                    else {
                        if (oObj.className && oObj.className == "AGE_Data") { 
                            var oTd;
                            var irowIndex = AppGridE1.GetSelectedRows();
                      
                            if(oObj.id=="KjkmCode")
                            {
                                 oTd = AppGridE1.GetTd(irowIndex, "KjkmName");
                            }

                            if(oObj.id=="KjkmName")
                            {
                                oTd = AppGridE1.GetTd(irowIndex, "ObjectDataTextShow");
                            }

                            if(oObj.id=="ObjectDataTextShow")
                            {
                                oTd = AppGridE1.GetTd(irowIndex, "HsxmObjectText");
                            }  

                           if(oObj.id=="HsxmObjectText"||oTd.innerHTML==  "<NOBR>　</NOBR>")
                            {
                                AppGridE1.event.returnValue=false;
                                if(AppGridE1.GetRowCount()-1>irowIndex)
                                {
				  setRowReadOnly(irowIndex, true);
                                  setRowReadOnly(irowIndex+1, false);                                  
                                  AppGridE1.FocusCell(irowIndex+1, "KjkmCode")
                                }
                            }

                            return;                
                        }
                        else {
                            oObj = oObj.parentElement;
                        }            
                    }
                }       
           } 
}

        //编辑
	    function openEdit() {
	        openWaiting();
	        setTimeout(openEdit1, 1)
	    }

	    function openEdit1() {
	        IsEdit = true;	    
	        deDisplay("scExport,scImport,scEdit");
	        reDisplay("scNew,scDelete,scSave");

	        var RowCount = AppGridE1.GetRowCount();
	        //解决业务数据超长的问题 liuk 2010-08-09
	        var sObjectData="";
	        var sObjectDataGUIDList ="";
	        var arrObjectData = AppGridE1.GetAttribute("ObjectData");
	        var arrObjectDataGUIDList=AppGridE1.GetAttribute("ObjectDataGUIDList");
	        
	        for (var i = 1; i < RowCount; i++) {
	            sObjectData=arrObjectData[i];	          
                sObjectDataGUIDList=arrObjectDataGUIDList[i];
                
	            if (sObjectDataGUIDList && sObjectDataGUIDList.split(",").length > 54) {
	                var sPath = "/PubProject/Cwjk/Cwjk_Kjkm_XMLHTTP.aspx?kjkmGUID=" + AppGridE1.GetAttribute("KjkmGUID", i);
	                var sReturn = openXMLHTTP(sPath, "GetCwjkKjkm2OperData");
	                if (sReturn && sReturn.substring(0, 2) == "OK") {
	                    var returnArray = sReturn.split("`");
	                    AppGridE1.SetAttribute("ObjectDataGUIDList", returnArray[1], i);
	                    AppGridE1.SetValue(i, "ObjectDataTextShow", returnArray[2]);
	                }
	            }
	        }

	      	AppGridE1.AppGridE_LeftDataDiv.firstChild.onkeydown = new Function( "KeyDown();");
	      	AppGridE1.AppGridE_RightDataDiv.firstChild.onkeydown = new Function("KeyDown();");

	        var lastIndex = AppGridE1.GetSelectedRows();

	        if (lastIndex == 0) {
	            lastIndex = 1;
	            AppGridE1.SelectRow(1);
	        }
	        setRowReadOnly(lastIndex, false);   
	        AppGridE1.FocusCell(lastIndex, "KjkmCode")
	        RefreshLevel();
	        
	        closeWaiting();
	    }

	    function setRowReadOnly(irowIndex, blReadonly) {
	        if (irowIndex > 0) {
	            AppGridE1.SetReadonly("KjkmCode", blReadonly, irowIndex);
	            AppGridE1.SetReadonly("KjkmName", blReadonly, irowIndex);

	            if (blReadonly) {
	                AppGridE1.SetReadonly("ObjectDataTextShow", true, irowIndex);
	                AppGridE1.SetReadonly("HsxmObjectText", true, irowIndex);
	            }
	            else {
	                var sRtn = GetEditStatusByIndex(irowIndex);
	                var  sRtnSplit = sRtn.split("&");
	            
	                if (sRtnSplit.length != 2) return;

 			if (sRtnSplit[1] == 1) AppGridE1.SetReadonly("ObjectDataTextShow", false, irowIndex);  
	                else  AppGridE1.SetReadonly("ObjectDataTextShow", true, irowIndex);  

	                if (sRtnSplit[0] == 1) AppGridE1.SetReadonly("HsxmObjectText", false, irowIndex);
	                else  AppGridE1.SetReadonly("HsxmObjectText", true, irowIndex);	               
	            }
	        }
	    }

	    function clickMe() {
	        if (IsEdit) {
	            var lastIndex = AppGridE1.GetSelectedRows();
	            var clkIndex = AppGridE1.event.rowIndex;
	            if (lastIndex == clkIndex) return;	          
	            setRowReadOnly(lastIndex, true);
	            setRowReadOnly(clkIndex, false);
	        }
	    }		    
	  	    
	    function GetEditStatusByIndex(sIndex)
	    {
	        var arrObjectType = AppGridE1.GetAttrsData("ObjectType");
	        var sIsEnd = AppGridE1.GetAttribute("IsEnd", sIndex);
	        var sKjkmOrderCode = AppGridE1.GetAttribute("KjkmOrderCode", sIndex);
	        var strObjectDataText = AppGridE1.GetCellsData("ObjectDataTextShow", sIndex, sIndex)[sIndex];
	      
	        //取得可编辑的辅助核算行
            var sHsEdit=0,sDataEdit=0;
            
            //对应末级科目的
            if (sIsEnd == "1" && strObjectDataText == "") 
            {
                sHsEdit = 1;  
            }	                          
            //对应业务对象的
            if (arrObjectType[sIndex] == "1") 
            {
                sHsEdit = 1;
            }    

	        //取得可编辑的系统业务数据行
	        j = 0;
	        var k,x,index,intIsEdit;	       
	            
            //对应末级科目的或对应业务对象的
	        if (sIsEnd == "1" || arrObjectType[sIndex] == "1") 
            {
                sDataEdit=1;
            }	                          
            else
            {
                var sCurKjkmOrderCode = sKjkmOrderCode;
                var ilastIndex=sCurKjkmOrderCode.lastIndexOf(".");
                //其他情况的
                intIsEdit=1;
                var arrSplit = sKjkmOrderCode.split(".");

                //先向上判断
                while (ilastIndex != -1)             
                {
                    sCurKjkmOrderCode = sCurKjkmOrderCode.substring(0, ilastIndex)

                    index = AppGridE1.FindAttrTr("KjkmOrderCode",sCurKjkmOrderCode,1);
                    if (arrObjectType[index] == "1") 
                    {
                        intIsEdit = 0;
                        break;
                    }
                    ilastIndex = sCurKjkmOrderCode.lastIndexOf(".");
                }
                if (intIsEdit==1)
                {
                    //再向下判断
                    x=1;
                    if (AppGridE1.GetRowCount() > sIndex+x)
                    {
                        while(AppGridE1.GetAttribute("KjkmOrderCode",sIndex+x).indexOf(sKjkmOrderCode) != -1)
                        {
                            
                            if (arrObjectType[sIndex+x] == "1")
                            {
                                intIsEdit = 0;
                                break;
                            }
                            x++;
                            if (AppGridE1.GetRowCount() <= sIndex+x) break;
                        }                  
                    }
                }
                   
                sDataEdit=intIsEdit;
            }
	        return sHsEdit + "&" + sDataEdit;
	    }

        //改变科目名称时，同步科目全称
        function ChangeKjkmFullName()
        {
            var arrTr = AppGridE1.GetSelectedRows();
            if (-1 == arrTr) return;
            //更改会计科目名称时，同步修改会计科目全称
            var strPreKjkmFullName = AppGridE1.GetAttribute("KjkmFullName",arrTr);
            var strPreKjkmOrderCode = AppGridE1.GetAttribute("KjkmOrderCode",arrTr);
            var strParentName = AppGridE1.GetAttribute("KjkmParentName",arrTr);
            AppGridE1.SetValue(arrTr,"KjkmName",AppGridE1.GetValue(arrTr,"KjkmName").replace(/(^\s*)|(\s*$)/g,""));
            var strKjkmName = AppGridE1.GetValue(arrTr,"KjkmName");
            var sIsEnd = AppGridE1.GetAttribute("IsEnd",arrTr);
            var strKjkmFullName;
            if (strParentName == "")
            {
                strKjkmFullName = strKjkmName;
            }
            else
            {
                strKjkmFullName = strParentName + '-' + strKjkmName;
            }
            AppGridE1.SetAttribute("KjkmFullName",strKjkmFullName,arrTr);
            
            sIsUpdate = true;
            //如果当前科目不是末级科目，还需要修改其子级科目的父级科目和科目全称
            if (sIsEnd != 1) 
            {
                var i,sNextKjkmFullName,sNextKjkmParentName,sNextKjkmOrderCode;
                var arrKjkmFullName = AppGridE1.GetAttrsData("KjkmFullName");
                var arrKjkmParentName = AppGridE1.GetAttrsData("KjkmParentName");
                var arrKjkmOrderCode = AppGridE1.GetAttrsData("KjkmOrderCode");
                var sNewKjkmFullName,sNewKjkmParentName;
                for (i=arrTr+1; i<arrKjkmFullName.length; i++)
                {
                    sNextKjkmFullName = arrKjkmFullName[i];
                    sNextKjkmParentName = arrKjkmParentName[i];
                    sNextKjkmOrderCode = arrKjkmOrderCode[i];
                    
                    if (sNextKjkmOrderCode.indexOf(strPreKjkmOrderCode) == 0)
                    {
                        sNewKjkmFullName = sNextKjkmFullName.replace(strPreKjkmFullName,strKjkmFullName);
                        AppGridE1.SetAttribute("KjkmFullName",sNewKjkmFullName,i);
                        
                        sNewKjkmParentName = sNextKjkmParentName.replace(strPreKjkmFullName,strKjkmFullName);
                        AppGridE1.SetAttribute("KjkmParentName",sNewKjkmParentName,i);                    
                    }
                    else break;
                }            
            }  
        }
        
        //会计科目编码重复性校验、
        //校验同级科目的名称（属于同一直接父级科目）是否重复
        //会计科目下X级科目的科目编码位数不一致，不允许保存！
        function ValidKjkmRepeat()
        {
            var arrKjkmCode,sKjkmCode,arrKjkmFullName,sKjkmFullName;
            var arrKjkmLevel,sKjkmLevel,sKjkmCodeLength;
            var i,j;
            arrKjkmCode = AppGridE1.GetCellsData("KjkmCode");
            arrKjkmFullName = AppGridE1.GetAttrsData("KjkmFullName");
            arrKjkmLevel = AppGridE1.GetAttrsData("KjkmLevel");
            for (i = 1; i < arrKjkmCode.length; i++) 
	        {
	            sKjkmCode = arrKjkmCode[i][0];
	            sKjkmFullName = arrKjkmFullName[i];
	            sKjkmLevel = arrKjkmLevel[i];
	            sKjkmCodeLength = sKjkmCode.length;
	            for (j = i+1; j < arrKjkmCode.length; j++)
	            {
	                if (sKjkmCode == arrKjkmCode[j][0])
	                {
	                    alert("会计科目编码" + sKjkmCode +"重复,不允许保存！");
	                    setRowReadOnly(j, false); 
	                    AppGridE1.FocusCell(j,"KjkmCode");
	                    return false;;	                
	                }
	                
	                if (sKjkmFullName == arrKjkmFullName[j])
	                {
	                //XX科目下存在重复的科目名称，不允许保存！
	                    var sParent = AppGridE1.GetAttribute("KjkmParentName",j)
	                    if (sParent == "") sParent="所有";
	                    else 
	                    {
	                        var arrParent = sParent.split("-");
	                        sParent = arrParent[arrParent.length - 1];
	                    }
	                
	                    alert(sParent+"科目下存在重复的科目名称，不允许保存！");
	                    setRowReadOnly(j, false);
	                    AppGridE1.FocusCell(j,"KjkmName");
	                    return false;;	                
	                }
	                
	                if (sKjkmLevel == arrKjkmLevel[j] && sKjkmCodeLength != arrKjkmCode[j][0].length)
	                {
	                    alert("会计科目下"+sKjkmLevel+"级科目的科目编码位数不一致，不允许保存！");
	                    setRowReadOnly(j, false); 
	                    AppGridE1.FocusCell(j,"KjkmCode");
	                    return false;;    
	                }
	            }
	        }        
            return true;
        }



        //科目编码、科目名称必填项校验
        function ValidDataBt()
        {
            var i;
            var RowCount=AppGridE1.GetRowCount();
        
	        var arrKjkmCode = AppGridE1.GetCellsData("KjkmCode");               //科目编码
	        var arrKjkmName = AppGridE1.GetCellsData("KjkmName");               //科目名称
	        for(i = 1; i < RowCount; i++)
	        {
		        if(arrKjkmCode[i][0] == "")
		        {
			        alert("请录入“会计科目编码”！");
			        setRowReadOnly(i, false); 
			        AppGridE1.FocusCell(i,"KjkmCode");
			        return false;
                }
                
                if (arrKjkmName[i] == "")
                {
                    alert("请录入“会计科目名称”！");
                    setRowReadOnly(i, false); 
                    AppGridE1.FocusCell(i, "KjkmName");
                    return false;
                }
	        }
	        return true;
        }

 	    //保存成功后操作，校验凭证规则异常
	    function oprAfterSave() 
	    {
            var sPath;
            sPath="/PubProject/Cwjk/Cwjk_Kjkm_XMLHTTP.aspx?CwztGUID="+document.getElementById("txtCwztGUID").value;
            var sReturn=openXMLHTTP(sPath,"GetErrorPzEntryCount");
            if (sReturn>0)
            {
                if(confirm("当前账套下存在" +sReturn +"条异常凭证规则，是否进行调整？"))
                {
                    sPath="/PubProject/Cwjk/Cwjk_PzRuleSet.aspx?CwztGUID="+document.getElementById("txtCwztGUID").value + "&Application=" +document.getElementById("txtApplication").value + "&IsYC=1&OperTypeGUID=";
                    var iX = 750;
				    var iY = 510;
				    OpenWin(sPath,iX,iY,1);
                }            
            }
 	    }
 	    
 	    //校验科目编码是否有非法字符
 	    function ValidKjkmCode()
 	    {
            var i,j;
            var RowCount=AppGridE1.GetRowCount();
            var sKjkmCode;
            var sAllowChars = "0123456789.-";
            
            for (j=1;j<RowCount;j++)
            {
                sKjkmCode = AppGridE1.GetValue(j,"KjkmCode")[0];
                for (i=0;i<sKjkmCode.length;i++)
                {
                    if (sAllowChars.indexOf(sKjkmCode.substring(i,i+1)) == -1)
                    {
                        alert("只允许录入以下字符：0～9 ,. ,-");
                        setRowReadOnly(j,false);
                        AppGridE1.FocusCell(j,"KjkmCode");
                        return false;   
                    }    
                }            
            }
            return true;
 	    }

        //重整系统业务数据，只需要将业务对象保存在会计科目表中
        function RebuildObjectDataText()
        {
            var i;
            var RowCount=AppGridE1.GetRowCount();
            var arrObjectType = AppGridE1.GetAttrsData("ObjectType");
            for (i=1;i<RowCount;i++)
            {
                if (arrObjectType[i] == 1) AppGridE1.SetAttribute("ObjectDataText",AppGridE1.GetValue(i,"ObjectDataTextShow"),i);
                else AppGridE1.SetAttribute("ObjectDataText","",i);
            }
        }
        
        //保存数据
        function Save()
        {  
            var lastIndex = AppGridE1.GetSelectedRows();
            setRowReadOnly(lastIndex, true);  
                   
            if(!ValidDataBt())
	        {
		        AppGridE1.event.returnValue = false;
		        return false;
	        }
	        
            if(!ValidKjkmCode())
	        {
		        AppGridE1.event.returnValue = false;
		        return false;
	        }

            if(!ValidKjkmRepeat())
	        {
		        AppGridE1.event.returnValue = false;
		        return false;
	        }

            RebuildObjectDataText();

            AppGridE1.Save();
            
            delCwjkKjkm2OperData();
            
            insertCwjkKjkm2OperData();
            
            delCwjkKjkm2Hsxm();
            
            insertCwjkKjkm2Hsxm();
            
            var sPath="/PubProject/Cwjk/Cwjk_Kjkm_XMLHTTP.aspx?CwztGUID="+document.getElementById("txtCwztGUID").value;
            var sReturn=openXMLHTTP(sPath,"CwjkKjkmUpdateKjkmCode");
            
            reDisplay("scExport,scImport,scEdit");
            deDisplay("scNew,scDelete,scSave");
            
	    AppGridE1.AppGridE_LeftDataDiv.firstChild.removeAttribute( "onkeydown");
	    AppGridE1.AppGridE_RightDataDiv.firstChild.removeAttribute( "onkeydown");
            
            //将所有行设为不可编辑
            AppGridE1.SetCellIsEdit("0",AppGridE1.GetAttribute("oid", AppGridE1.GetSelectedRows()));
            AppGridE1.Refresh();
            sIsUpdate = false;
            IsEdit = false;	 
            return true;
        }
        
        //删除当前账套下的会计科目2业务数据（p_CwjkKjkm2OperData）
        function delCwjkKjkm2OperData()
        {
            var sPath="/PubProject/Cwjk/Cwjk_Kjkm_XMLHTTP.aspx?CwztGUID="+document.getElementById("txtCwztGUID").value;
            var sReturn=openXMLHTTP(sPath,"DelCwjkKjkm2OperData");
        
        }
        
        //新增会计科目2业务数据（p_CwjkKjkm2OperData）
        function insertCwjkKjkm2OperData()
        { 
            var i,isInsert=0;
            var RowCount=AppGridE1.GetRowCount();
            var strPara = "";
            var strObjectKjkmFullName;
        
	        var arrObjectDataText = AppGridE1.GetCellsData("ObjectDataTextShow");               //系统业务数据
	        var arrObjectDataGUIDList = AppGridE1.GetAttrsData("ObjectDataGUIDList");       //业务数据GUID
	        var arrObjectKjkmGUID = AppGridE1.GetAttrsData("ObjectKjkmGUID");               //对应业务对象的科目GUID
	        var arrIsEnd = AppGridE1.GetAttrsData("IsEnd");                                 //是否末级
	        var arrObjectData = AppGridE1.GetAttrsData("ObjectData");                       //所属业务对象
	        var arrKjkmGUID = AppGridE1.GetAttrsData("KjkmGUID");                           //会计科目GUID
	        var arrObjectType = AppGridE1.GetAttrsData("ObjectType");                       //数据类型
	        var arrIsNew = AppGridE1.GetAttrsData("IsNew");                                 //是否新增
	        var arrKjkmFullName = AppGridE1.GetAttrsData("KjkmFullName");                   //科目全称

            var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
            xmlDoc.loadXML('<?xml version="1.0" encoding="gb2312" ?><Kjkm2OperData></Kjkm2OperData>');

	        for(i = 1; i < RowCount; i++)
	        {
		        if(arrIsEnd[i] == 1 && arrObjectDataText[i] != "" && arrObjectType[i] == 2)
		        {	            
		            if (arrObjectKjkmGUID[i] == "") arrObjectKjkmGUID[i]=getObjectKjkmGUID(i);
		            strObjectKjkmFullName = getObjectKjkmFullName(i);
		            
                    var Item = xmlDoc.createElement("Item");
                    Item.setAttribute("KjkmGUID",arrKjkmGUID[i]);
                    Item.setAttribute("ObjectData",arrObjectData[i]);
                    Item.setAttribute("ObjectDataGUIDList",arrObjectDataGUIDList[i]);
                    Item.setAttribute("ObjectDataText",arrObjectDataText[i]);
                    Item.setAttribute("ObjectKjkmGUID",arrObjectKjkmGUID[i]);
                    Item.setAttribute("IsNew",arrIsNew[i]);
                    Item.setAttribute("ObjectKjkmFullName",strObjectKjkmFullName);
                    Item.setAttribute("KjkmFullName",arrKjkmFullName[i]);
                    xmlDoc.documentElement.appendChild(Item);
		            isInsert=1;
                }
 	        }

            if (isInsert == 1)
            {
                var sPath="/PubProject/Cwjk/Cwjk_Kjkm_XMLHTTP.aspx?CwztGUID="+document.getElementById("txtCwztGUID").value;
                var sReturn=openXMLHTTP(sPath,"InsertCwjkKjkm2OperData",xmlDoc.xml);            
            }
        //******************************************************************************************
        }

        //删除当前删除下的会计科目2辅助核算关系数据（p_CwjkKjkm2Hsxm）
        function delCwjkKjkm2Hsxm()
        {
            var sPath="/PubProject/Cwjk/Cwjk_Kjkm_XMLHTTP.aspx?CwztGUID="+document.getElementById("txtCwztGUID").value;
            var sReturn=openXMLHTTP(sPath,"DelCwjkKjkm2Hsxm");
        }

        //新增会计科目2辅助核算关系数据
        function insertCwjkKjkm2Hsxm()
        {
            var i,isInsert=0;
            var RowCount=AppGridE1.GetRowCount();
            var strPara = "";
        
	        var arrHsxmObjectText = AppGridE1.GetCellsData("HsxmObjectText");               //辅助核算
	        var arrHsxmGUIDList = AppGridE1.GetAttrsData("HsxmGUIDList");                   //辅助核算GUID
	        var arrKjkmGUID = AppGridE1.GetAttrsData("KjkmGUID");                           //会计科目GUID
            var arrIsNew = AppGridE1.GetAttrsData("IsNew");                                 //是否新增
            var arrKjkmFullName = AppGridE1.GetAttrsData("KjkmFullName");                   //科目全称
            
            var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
            xmlDoc.loadXML('<?xml version="1.0" encoding="gb2312" ?><Kjkm2OperData></Kjkm2OperData>');
            
	        for(i = 1; i < RowCount; i++)
	        {
		        if(arrHsxmGUIDList[i] != "")
		        {
		            var Item = xmlDoc.createElement("Item");
                    Item.setAttribute("KjkmGUID",arrKjkmGUID[i]);
		            Item.setAttribute("HsxmGUIDList",arrHsxmGUIDList[i]);
		            Item.setAttribute("IsNew",arrIsNew[i]);
		            Item.setAttribute("KjkmFullName",arrKjkmFullName[i]);
		            xmlDoc.documentElement.appendChild(Item);
		            isInsert=1;
                }
 	        }

            if (isInsert == 1)
            {
                var sPath="/PubProject/Cwjk/Cwjk_Kjkm_XMLHTTP.aspx?CwztGUID="+document.getElementById("txtCwztGUID").value;
                var sReturn=openXMLHTTP(sPath,"InsertCwjkKjkm2Hsxm",xmlDoc.xml);            
            }
        }
        


        //取得对应业务对象的科目GUID
        function getObjectKjkmGUID(CurrentRow)
        {   
            var i;
            for(i=CurrentRow-1;i>0;i--)
            {
                if (AppGridE1.GetAttribute("ObjectType",i) ==1)
                {
                    return AppGridE1.GetAttribute("KjkmGUID",i)
                }
            }
        }

        //取得对应业务对象的科目全称
        function getObjectKjkmFullName(CurrentRow)
        {   
            var i;
            for(i=CurrentRow-1;i>0;i--)
            {
                if (AppGridE1.GetAttribute("ObjectType",i) ==1)
                {
                    return AppGridE1.GetAttribute("KjkmFullName",i)
                }
            }
        }

        //删除行
        function delRow()
        {
            var arrTr = AppGridE1.GetSelectedRows();
            if (-1 == arrTr) return;
            
            //根节点不允许删除
            var sIsSys = AppGridE1.GetAttribute("IsSys",arrTr);
            if (sIsSys == 2) return;

            //系统默认科目不允许删除
            if (sIsSys == 1)
            {
                alert("当前科目为系统默认的一级科目，不允许删除！");
                return;
            }

            //被引用的科目不允许删除
            var sPath="/PubProject/Cwjk/Cwjk_Kjkm_XMLHTTP.aspx?CwztGUID="+AppGridE1.GetAttribute("CwztGUID",arrTr)+"&KjkmOrderCode="+AppGridE1.GetAttribute("KjkmOrderCode",arrTr);
            var sReturn=openXMLHTTP(sPath,"GetUsedKjkmName");
            if (sReturn != "")
            {
                alert(sReturn + "已被凭证规则引用，不允许删除！");
                return;
            }
            
            
            if (confirm("确实要删除选择的科目和子级科目吗?") == false) return;

            var i=arrTr,j=0;
            var arrDelRow = [];
            var strKjkmOrderCode = AppGridE1.GetAttribute("KjkmOrderCode",arrTr);
            var strKjkmLevel = AppGridE1.GetAttribute("KjkmLevel",arrTr);
            var strNextKjkmOrderCode,strNextKjkmLevel;
            do
            {
                arrDelRow[j++]=i;
                i++;
                if (AppGridE1.GetRowCount() <= i) break;
                strNextKjkmOrderCode = AppGridE1.GetAttribute("KjkmOrderCode",i);
                strNextKjkmLevel = AppGridE1.GetAttribute("KjkmLevel",i);
            }
            while(strNextKjkmOrderCode.indexOf(strKjkmOrderCode) == 0 && strNextKjkmLevel>strKjkmLevel);
      
            AppGridE1.DelRow(false,arrDelRow);
   
            //将删除行的父级置为末级科目
            if (arrTr > 1)
            {
                var sNewParentCode=GetParentKjkmOrderCode(strKjkmOrderCode);
                var index = AppGridE1.FindAttrTr("KjkmOrderCode",sNewParentCode,1);
                
                if (AppGridE1.GetRowCount() <= index+1)
                {
                    AppGridE1.SetAttribute("IsEnd",1,index);
                }
                else
                {
                    if (AppGridE1.GetAttribute("KjkmOrderCode",index+1).indexOf(sNewParentCode) ==-1)
                    {
                       AppGridE1.SetAttribute("IsEnd",1,index);
                    }
                }
                index = AppGridE1.GetSelectedRows();
                //重新整理可编辑行
                setRowReadOnly(index,false);                
            }
            
            sIsUpdate = true;

            
        }
        
        function GetParentKjkmOrderCode(strKjkmOrderCode)
        {
            var arrSplitCode = strKjkmOrderCode.split(".");
            var sParentCode="";
            var sNewParentCode;
            for (i=0;i<arrSplitCode.length-1;i++)
            {
                sParentCode = sParentCode + arrSplitCode[i] + ".";
            }
            sNewParentCode=sParentCode.substr(0,sParentCode.length-1);
        
            return sNewParentCode;
        }
        
        //取得本机编码////////////////////////////////////////////
        function getShortCode(arrTr,sKjkmLevel)
        {
            var RowCount=AppGridE1.GetRowCount();
            var i,j;
            var sOrderCode = AppGridE1.GetAttribute("OrderCode",arrTr);
            var sSonOrderCode,sSonKjkmLevel,sSonShortCode="001",sNextShortCode;
            for (i=arrTr+1;i<RowCount;i++)
            {
                sSonOrderCode=AppGridE1.GetAttribute("OrderCode",i);
                sSonKjkmLevel=AppGridE1.GetAttribute("KjkmLevel",i);
                sNextShortCode=AppGridE1.GetAttribute("ShortCode",i);
                
                if (sSonOrderCode.indexOf(sOrderCode)==0)
                {
                    if (sSonKjkmLevel==sKjkmLevel+1 && sSonShortCode < sNextShortCode) sSonShortCode=sNextShortCode;                
                }
                else break;           
            }
            j = parseInt(sSonShortCode,10)+1
            switch (String(j).length)
            {
                case 1:
                    sSonShortCode = "00" + String(j);
                    break;
                case 2:
                    sSonShortCode = "0" + String(j);
                    break;
                case 3:
                    sSonShortCode = String(j);
                    break;
            
            }
            return sSonShortCode
        }

        //添加行
        function addRow()
        {
            var arrTr = AppGridE1.GetSelectedRows();
            if (-1 == arrTr) return;
            
            var arrAttribute=[];
            var arrCell=[];
            var sKjkmOrderCode;
            
            sKjkmOrderCode = AppGridE1.GetAttribute("KjkmOrderCode",arrTr);

            arrAttribute[0]=document.getElementById("txtBUGUID").value;
            arrAttribute[1]=document.getElementById("txtCwztGUID").value;
            arrAttribute[2]=openXMLHTTP("/PubProject/Cwjk/Cwjk_Kjkm_XMLHTTP.aspx","GetNewGUID");//用NewId()
            arrAttribute[3]=AppGridE1.GetAttribute("KjkmFullName",arrTr);
            arrAttribute[4]=AppGridE1.GetAttribute("KjkmFullName",arrTr);
            arrAttribute[5]=parseInt(AppGridE1.GetAttribute("KjkmLevel",arrTr)) + 1;
            arrAttribute[6]=sKjkmOrderCode;
            
            //取得本级代码
            var sReturn=getShortCode(arrTr,parseInt(AppGridE1.GetAttribute("KjkmLevel",arrTr)));
            
            arrAttribute[7]=sReturn;
            
            var strKjkmOrderCode;
            var lastKjkmOrderCode = sKjkmOrderCode;
            if (lastKjkmOrderCode == '')
            {
                strKjkmOrderCode = sReturn;
            }
            else
            {
                strKjkmOrderCode =lastKjkmOrderCode + '.' + sReturn
            }
            arrAttribute[8]=strKjkmOrderCode;
            arrAttribute[9]=AppGridE1.GetAttribute("ObjectData",arrTr);
            arrAttribute[10]=0;
            arrAttribute[11]=1;
            arrAttribute[12]=0;
            arrAttribute[13]="0." + strKjkmOrderCode;
            arrAttribute[14]="";
            arrAttribute[15]="";
            arrAttribute[16]=AppGridE1.GetAttribute("ObjectKjkmGUID",arrTr);
            arrAttribute[17]=1;
            arrAttribute[18]="";
            
            arrCell[0] = [];					
	        arrCell[0][0] = "";
            arrCell[0][1]="0." + strKjkmOrderCode;
            arrCell[1]="";
            arrCell[2]="";
            arrCell[3]="";
            
            //找到要添加的位置//////////////////////////////////////////
            var RowCount=AppGridE1.GetRowCount();
            var i;
            
            if (arrTr==0) i=RowCount;
            else
            {
                for (i=arrTr+1;i<RowCount;i++)
                {
                    if (AppGridE1.GetAttribute("KjkmOrderCode",i).indexOf(sKjkmOrderCode)==-1) break;          
                }            
            }
            //添加行
            AppGridE1.AddRow(arrAttribute,arrCell,i);
            
            //重设原来行的值            
            if (arrTr!=0)
            {
                AppGridE1.SetAttribute("IsEnd",0,arrTr);
                AppGridE1.SetAttribute("ObjectDataGUIDList","",arrTr);
                AppGridE1.SetAttribute("ObjectKjkmGUID","",arrTr);
            } 
                   
            AppGridE1.SelectRow(arrTr);

            //原来行对应的不是业务对象时
            if (AppGridE1.GetAttribute("ObjectType",arrTr)!=1 && arrTr!=0)
            {
                AppGridE1.SetValue(arrTr,"ObjectDataTextShow","");
                AppGridE1.SetValue(arrTr,"HsxmObjectText","");
                AppGridE1.SetAttribute("HsxmGUIDList","",arrTr);
                AppGridE1.SetAttribute("ObjectType",0,arrTr);
            }

            sIsUpdate = true;
          
            //重新整理可编辑行      
            setRowReadOnly(arrTr,false)         
        }

        //取得过滤业务数据
        function getObjectFilter(sObjectKjkmGUID,sKjkmGUID)
        {
            var index = AppGridE1.FindAttrTr("KjkmGUID",sObjectKjkmGUID,1);
            var sKjkmOrderCode = AppGridE1.GetAttribute("KjkmOrderCode",index);
            var rowCount = AppGridE1.GetRowCount();
            var sDataName="";
            var sDataGUID="";
            var sCurrentDataName,sCurrentDataGUID;
            var sFgf="";
            var x;
            
            for (x=index+1;x<rowCount;x++)
            {
                if (AppGridE1.GetAttribute("KjkmOrderCode",x).indexOf(sKjkmOrderCode) == -1) break;
                if (AppGridE1.GetAttribute("KjkmGUID",x) == sKjkmGUID) continue;
                
                sCurrentDataName = AppGridE1.GetValue(x,"ObjectDataTextShow");
                sCurrentDataGUID = AppGridE1.GetAttribute("ObjectDataGUIDList",x)
                
                if (AppGridE1.GetAttribute("IsEnd",x) == 1 && sCurrentDataName != "")
                {
                    if (sDataName == "") sFgf = "";
                    else sFgf = ",";
                    
                    sDataName = sDataName + sFgf + sCurrentDataName;
                    sDataGUID = sDataGUID + sFgf + sCurrentDataGUID;
                }
            }
            return sDataGUID + "|" + sDataName;
        }

        //选择系统业务数据事件
        function selectData()
        {
            var arrTr = AppGridE1.event.rowIndex;
        	var strPath = "";
	        var strParamList = ""; 
	        var sObjectFilter = "" ;
	        var sParamList = "";
	        var sSelectObject = "";
	        var x;  
	        var sSessionPath,sSessionReturn,sSessionPara;

	        var sObjectData = AppGridE1.GetAttribute("ObjectData",arrTr);
	        var sObjectDataGUIDList = AppGridE1.GetAttribute("ObjectDataGUIDList",arrTr);
	        var sKjkmLevel = AppGridE1.GetAttribute("KjkmLevel",arrTr);
	        var sKjkmGUID = AppGridE1.GetAttribute("KjkmGUID",arrTr);
            var sIsEnd = AppGridE1.GetAttribute("IsEnd",arrTr);
            var sKjkmOrderCode = AppGridE1.GetAttribute("KjkmOrderCode",arrTr);
            var sIniObjectType = AppGridE1.GetAttribute("ObjectType",arrTr);    //原值
            var sObjectKjkmGUID = AppGridE1.GetAttribute("ObjectKjkmGUID",arrTr);
            var sObjectDataText = AppGridE1.GetValue(arrTr,"ObjectDataTextShow");
            
            if (sIniObjectType == 1 || sIsEnd != 1 || (sIsEnd ==1 && sObjectData == ""))  //选择业务对象
            {
	            strPath="/PubProject/Cwjk/Cwjk_SelectOperObject.aspx";
	            strParamList = "Application=" + document.getElementById("txtApplication").value + "&OperObject=" + sObjectData;
	            var arrRtn = openMyDlg("选择业务对象", strPath, strParamList, "", 300, 450);
	            
	            if(arrRtn != undefined)
	            { 
	                if (arrRtn == "")       //清空
	                {
	                    if (sIniObjectType == 0) return;    //如果原本就是空值，清空则不做操作
	                    AppGridE1.SetValue(arrTr,"ObjectDataTextShow","");
	                    AppGridE1.SetAttribute("ObjectData","",arrTr);
	                    AppGridE1.SetAttribute("ObjectType",0,arrTr);

	                    //同步清空非末级的辅助核算
                        x = 0;
                        while(AppGridE1.GetAttribute("KjkmOrderCode",arrTr+x).indexOf(sKjkmOrderCode) != -1)
                        {
                            if (AppGridE1.GetAttribute("IsEnd",arrTr+x) != 1)
                            {
	                            AppGridE1.SetValue(arrTr+x,"HsxmObjectText","");
	                            AppGridE1.SetAttribute("HsxmGUIDList","",arrTr+x);                            
                            }
                            x++;
                            if (AppGridE1.GetRowCount() <= arrTr+x) break;
                        }                     
	                }
	                else                    //选择业务对象
	                {
	                    if (sObjectData == arrRtn) return;      //如果原来的业务对象和本次选择的业务对象相同，则直接退出
	                    
	                    AppGridE1.SetAttribute("ObjectType",1,arrTr);
	                    AppGridE1.SetValue(arrTr,"ObjectDataTextShow","【" + arrRtn + "】"); 
	                    AppGridE1.SetAttribute("ObjectData",arrRtn,arrTr);

	                    //同步设置子级的ObjectKjkmGUID为当前科目GUID
                        x = 0;
                        while(AppGridE1.GetAttribute("KjkmOrderCode",arrTr+x).indexOf(sKjkmOrderCode) != -1)
                        {
                            AppGridE1.SetAttribute("ObjectKjkmGUID",sKjkmGUID,arrTr+x);
                            
                            x++;
                            if (AppGridE1.GetRowCount() <= arrTr+x) break;
                        } 
	                }

	                //对其子级的ObjectData,ObjectType赋值  
                    x = 1;
                    if (AppGridE1.GetRowCount() > arrTr+x)
                    {
                        while(AppGridE1.GetAttribute("KjkmOrderCode",arrTr+x).indexOf(sKjkmOrderCode) != -1)
                        {
                            AppGridE1.SetAttribute("ObjectData",arrRtn,arrTr+x);
                            AppGridE1.SetAttribute("ObjectType",0,arrTr+x);
                            AppGridE1.SetAttribute("ObjectDataGUIDList","",arrTr+x);
//                          AppGridE1.SetAttribute("ObjectKjkmGUID","",arrTr+x);
                            AppGridE1.SetValue(arrTr+x,"ObjectDataTextShow","");

                            x++;
                            if (AppGridE1.GetRowCount() <= arrTr+x) break;
                        }                     
                    }
                    sIsUpdate = true;
	            }	            
            }
            
            
            else                    //选择业务数据
            {
                var returnArray;
                var arrReturn;
                if (sObjectKjkmGUID == "") sObjectKjkmGUID = getObjectKjkmGUID(arrTr);
                var sReturn = getObjectFilter(sObjectKjkmGUID,sKjkmGUID);
                if (sReturn != undefined) arrReturn = sReturn.split("|");
                
                if (document.getElementById("txtApplication").value == "0101")      //售楼
                {
                    switch(sObjectData)
                    {
                        case "入账银行":                                 //常规列表
                        case "票据类型":
                        case "项目名称+票据类型":
                        case "一级产品类型+票据类型":                                           
                            sObjectFilter = arrReturn[1];
                            sSelectObject = sObjectDataText;
                            
                            sParamList = "ObjectType=" + escape(sObjectData) + "&ObjectFilter=" + escape(sObjectFilter) + "&SelectObject=" + escape(sSelectObject);

                            if (document.getElementById("__CwztGUID"))
                            {
                              sParamList += "&CwztGUID=" + escape(document.getElementById("__CwztGUID").value);
                            }

                            returnArray = OpenModalWin("选择" + sObjectData, "/PubProject/Cwjk/Cwjk_SelectObjectDataForKJKM.aspx", sParamList, 360, 500);
                            break;
                        case "产品类型全称":                                    //树形列表   
                        case "款项名称":
                        case "楼栋名称":
                        case "项目名称":  
                            if (sObjectData == "款项名称") 
                            {
                                sObjectFilter = arrReturn[1];
                                sSelectObject = sObjectDataText;
                            }
                            else 
                            {
                                sObjectFilter = arrReturn[0];
                                sSelectObject = sObjectDataGUIDList;
                            }

                            //将较长参数传入Session保存
                            sSessionPath="/PubProject/Cwjk/Cwjk_Kjkm_XMLHTTP.aspx";
                            openXMLHTTP(sSessionPath,"SaveSessionObjectFilter",sObjectFilter);
                            openXMLHTTP(sSessionPath,"SaveSessionSelectObject",sSelectObject);
                            
                            sParamList = "ObjectType=" + escape(sObjectData)
                            if (document.getElementById("__CwztGUID"))
                            {
                              sParamList += "&CwztGUID=" + escape(document.getElementById("__CwztGUID").value);
                            }
                            
                            returnArray = OpenModalWin("选择" + sObjectData, "/PubProject/Cwjk/Cwjk_SelectObjectDataForKJKM2.aspx", sParamList, 360, 500);
                            break;
                            
                    }

                 }   
                 else if(document.getElementById("txtApplication").value == "0201") //成本
                 {
                    switch(sObjectData)
                    {
                        case "产品":
                        case "款项类型":
                        case "付款银行":                                          //常规列表
                            if (sObjectData == "产品") 
                            {
                                sObjectFilter = arrReturn[0];
                                sSelectObject = sObjectDataGUIDList;
                            }
                            else 
                            {
                                sObjectFilter = arrReturn[1];
                                sSelectObject = sObjectDataText;
                            }
                            sParamList = "ObjectType=" + escape(sObjectData) + "&ObjectFilter=" + escape(sObjectFilter) + "&SelectObject=" + escape(sSelectObject);

                            if (document.getElementById("__CwztGUID"))
                            {
                              sParamList += "&CwztGUID=" + escape(document.getElementById("__CwztGUID").value);
                            }
                            
                            returnArray = OpenModalWin("选择" + sObjectData, "/PubProject/Cwjk/Cwjk_SelectObjectDataForKJKM.aspx", sParamList, 360, 500);
                            break;
                        case "项目名称":                                                            //树形列表  
                            sObjectFilter = arrReturn[0];
                            sSelectObject = sObjectDataGUIDList;     

                            //将较长参数传入Session保存
                            sSessionPath="/PubProject/Cwjk/Cwjk_Kjkm_XMLHTTP.aspx";
                            openXMLHTTP(sSessionPath,"SaveSessionObjectFilter",sObjectFilter);
                            openXMLHTTP(sSessionPath,"SaveSessionSelectObject",sSelectObject);
                            
                            sParamList = "ObjectType=" + escape(sObjectData)
                            
                            if (document.getElementById("__CwztGUID"))
                            {
                              sParamList += "&CwztGUID=" + escape(document.getElementById("__CwztGUID").value);
                            }
                            
                            returnArray = OpenModalWin("选择" + sObjectData, "/PubProject/Cwjk/Cwjk_SelectObjectDataForKJKM2.aspx", sParamList, 360, 500);
                            break;
                            
                        case "成本科目":                                                            //成本科目
                            sObjectFilter = arrReturn[0];
                            sSelectObject = sObjectDataGUIDList;    

                            //将较长参数传入Session保存
                            sSessionPath="/PubProject/Cwjk/Cwjk_Kjkm_XMLHTTP.aspx";
                            openXMLHTTP(sSessionPath,"SaveSessionObjectFilter",sObjectFilter);
                            openXMLHTTP(sSessionPath,"SaveSessionSelectObject",sSelectObject);
                            
                            sParamList = "ObjectType=" + escape(sObjectData)
                            if (document.getElementById("__CwztGUID"))
                            {
                              sParamList += "&CwztGUID=" + escape(document.getElementById("__CwztGUID").value);
                            }
                            returnArray = OpenModalWin("选择" + sObjectData, "/PubProject/Cwjk/Cwjk_SelectObjectDataForKJKM3.aspx", sParamList, 550, 700);
                            break;
                    }
                 
                 }

                if (returnArray)
                {
                    AppGridE1.SetAttribute("ObjectDataGUIDList",returnArray[1],arrTr);
                    AppGridE1.SetValue(arrTr,"ObjectDataTextShow",returnArray[0]); 
                    if (returnArray[0]=="") AppGridE1.SetAttribute("ObjectType",0,arrTr);
                    else AppGridE1.SetAttribute("ObjectType",2,arrTr);
                    
                    //原来系统业务数据为空，现在选择了业务数据，需要将对应的辅助核算清空
                    if (sObjectDataGUIDList == "" && returnArray[0] != "" && sKjkmLevel>1)  
                    {
                        AppGridE1.SetAttribute("HsxmGUIDList","",arrTr);
                        AppGridE1.SetValue(arrTr,"HsxmObjectText",""); 
                    }                                   

                    sIsUpdate = true;
                }
            }
    
            //重新整理可编辑行
            setRowReadOnly(arrTr, false);
        }

        //选择辅助核算
        function selectHs()
        {
            var arrTr = AppGridE1.event.rowIndex;
        	var strPath = "";
	        var strParamList = ""; 
	        
	        var sHsxmGUIDList = AppGridE1.GetAttribute("HsxmGUIDList",arrTr);
	        var sKjkmOrderCode = AppGridE1.GetAttribute("KjkmOrderCode",arrTr);
	        
            strPath="/PubProject/Cwjk/Cwjk_SelectHs.aspx";
            strParamList = "CwztGUID=" + document.getElementById("txtCwztGUID").value + "&HsTypeGUID_List=" + sHsxmGUIDList;
            strParamList = strParamList + "&CwztName=" + document.getElementById("txtCwztName").value;
            strParamList = strParamList + "&Application=" + document.getElementById("txtApplication").value;
            strParamList = strParamList + "&funcid=" + document.getElementById("txtfuncid").value;
            
            var arrRtn = openMyDlg("选择辅助核算", strPath, strParamList, "",350, 440);
            
        	if(arrRtn != undefined)
            {
                var arrSplit = arrRtn.split("|");
                //只对对本级HsxmGUIDList、HsxmObjectText赋值
                AppGridE1.SetAttribute("HsxmGUIDList",arrSplit[0],arrTr);
                AppGridE1.SetValue(arrTr,"HsxmObjectText",arrSplit[1])  
                      
                sIsUpdate = true;             
            }
    
        }

        //刷新级数
        function RefreshLevel()
        {
            if (AppGridE1.GetMaxLevel()==undefined) return;
	        if(MaxLevel != AppGridE1.GetMaxLevel())
	        {
		        var sHtml="";
		        var i,j;
		        MaxLevel = AppGridE1.GetMaxLevel();
		        if(MaxLevel > 1)
			        for(i = 1; i < MaxLevel; i++)
			        {
			            j=i+1;
				        sHtml += "<a href='#' onclick='javascript:AppGridE1.ShowLevel(" + j + ")' style='color:white;text-decoration: none' >&nbsp;" + i + "&nbsp;</a>";
        		    
        		    }
		        document.all("spanLevel1").innerHTML = sHtml;
	        }
        }

		//导出为Excel
		function ExportKjkm()
		{
			var sTitle, sHeight, sFile, sParams;

			sTitle = "导出会计科目";
			sHeight = "";
			sFile = "/PubProject/Cwjk/Cwjk_Kjkm_Template_Export.aspx";
			sWidth = "326";
			sHeight = "160";
			sParams="CwztGUID="+document.getElementById("txtCwztGUID").value+"&CwztName="+document.getElementById("txtCwztName").value;

			var url = "/FrameTemp0.aspx";
			url += "?title=" + escape(sTitle);
			url += "&filename=" + escape(sFile);					
            url += "&param=" + escape(sParams);
			var sReturnValue = window.showModalDialog(url, "", "dialogWidth:" + sWidth + "px; dialogHeight:" + sHeight + "px; status:no; help:no; resizable:no;scroll:no;");
		}
		
		function InportKjkm()
		{

		    var sTitle, sHeight, sFile, sParams;
		    sTitle = "导入会计科目";
		    sHeight = "";
		    sFile = "/PubProject/Cwjk/Cwjk_Kjkm_Template_Import.aspx";
		    sWidth = "380";
		    sHeight = "170";
		    sParams="CwztGUID="+document.getElementById("txtCwztGUID").value;
		    var url = "/FrameTemp0.aspx";
		    url += "?title=" + escape(sTitle);
		    url += "&filename=" + escape(sFile);
		    url += "&param=" + escape(sParams);
		    var sReturnValue = window.showModalDialog(url, "", "dialogWidth:" + sWidth + "px; dialogHeight:" + sHeight + "px; status:no; help:no; resizable:no;scroll:no;");
		    if (sReturnValue=="OK" )
		    {						
			    AppGridE1.Refresh();
			    //异常校验
			    oprAfterSave();
		    }
		}
		

        function ChangeKjkmCode()
        { 
            var arrTr = AppGridE1.event.rowIndex;
            var arrKjkmCode = [];
            arrKjkmCode[0] = AppGridE1.GetValue(arrTr,"KjkmCode")[0].replace(/(^\s*)|(\s*$)/g,"");
            arrKjkmCode[1] = AppGridE1.GetValue(arrTr,"KjkmCode")[1];
            AppGridE1.SetValue(arrTr,"KjkmCode",arrKjkmCode);
            
            var sAllowChars = "0123456789.-";
            var i;
            for (i=0;i<arrKjkmCode[0].length;i++)
            {
                if (sAllowChars.indexOf(arrKjkmCode[0].substring(i,i+1)) == -1)
                {
                    alert("只允许录入以下字符：0～9 ,. ,-");
                    
                    setRowReadOnly(arrTr,false);                    
                    AppGridE1.FocusCell(arrTr,"KjkmCode");
                    return false;   
                }    
            }
            
            sIsUpdate = true;
        }

        //如果已修改数据，关闭窗体时提示是否保存
        function window.onbeforeunload() 
        {
            if (sIsUpdate && sIsShowMsg==1) 
            {
                 window.event.returnValue = "------------------------------------------------------\n确定后，将不保存会计科目的调整，直接关闭当前页面。\n------------------------------------------------------";
            }
        }

	</script>
  </head>
  <body>
		<form id="Form1" runat="server">
			<input id="htmlSpanLevel" type="hidden" name="htmlSpanLevel" runat="server">
			<asp:textbox id="txtCwztGUID" style="display:none" Runat="server"></asp:textbox>
            <asp:textbox id="txtBUGUID" style="display:none" Runat="server"></asp:textbox>
            <asp:textbox id="txtApplication" style="display:none" Runat="server"></asp:textbox>
            <asp:textbox id="txtCwztName" style="display:none" Runat="server"></asp:textbox>
            <asp:textbox id="txtfuncid" style="display:none" Runat="server"></asp:textbox>
          
			<iframe id="refreshIframe" style="DISPLAY:none"></iframe><!-- 打印屏幕报表使用 -->
		</form>
		<table style="FONT-SIZE: 9pt" height="100%" cellSpacing="0" cellPadding="0" width="100%"
			border="0">
			<tr height="1">
				<td><mnu:appgridmenu id="appGridMenu1" runat="server"></mnu:appgridmenu></td>
			</tr>
			<tr height="98%">
				<td vAlign="top">
					<cc1:AppGridE id="AppGridE1" runat="server"></cc1:AppGridE>
				</td>
			</tr>
		</table>
	</body>
</html>